#include "Headers.h"
#include "UIImage.h"


CUIImage::CUIImage(void)
{
}


CUIImage::~CUIImage(void)
{
}


bool CUIImage::Initialize(int resource, int x, int y)
{
	m_Image = LoadBitmap(g_hInst, MAKEINTRESOURCE(resource));

	if(m_Image == NULL)
		return false;

	GetObject(m_Image, sizeof(BITMAP), &m_ImageInfo);
	m_x = x;
	m_y = y;
	m_width = x+m_ImageInfo.bmWidth;
	m_height = y+m_ImageInfo.bmHeight;
	return true;
}

void CUIImage::Uninitialize()
{
	DeleteObject(m_Image);
}

void CUIImage::Render(HDC hdc)
{
	HDC MemDC = CreateCompatibleDC(hdc);
	HBITMAP OldBitmap = (HBITMAP)SelectObject(MemDC, m_Image);
	
	TransparentBlt(hdc, m_x, m_y, m_width, m_height, MemDC, 0, 0, m_width, m_height,
		RGB(255, 0, 255));

	SelectObject(MemDC, OldBitmap);
	DeleteDC(MemDC);
}

void CUIImage::AlphaRender(HDC hdc, int alpha)
{
	HDC MemDC = CreateCompatibleDC(hdc);
	HBITMAP OldBitmap = (HBITMAP)SelectObject(MemDC, m_Image);

	BLENDFUNCTION bfn;
	bfn.AlphaFormat = 0;
	bfn.BlendFlags = 0;
	bfn.BlendOp = AC_SRC_OVER;
	bfn.SourceConstantAlpha = alpha;

	AlphaBlend(hdc, m_x, m_y, m_width, m_height, 
		MemDC, 0, 0, m_ImageInfo.bmWidth, m_ImageInfo.bmHeight, bfn);

	SelectObject(MemDC, OldBitmap);
	DeleteDC(MemDC);
}